package com.zh.spring.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

/**
 * 描述：com.zh.spring.service
 *
 * @author 80002023
 *         2016/12/29.
 * @version 1.0
 * @since 1.8
 */
@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private JdbcTemplate jdbcTemplate;


    @Override
    public void create(String name, String password) {
        jdbcTemplate.update("insert into USERS(USERNAME, PASSWORD) values(?, ?)", name, password);
    }

    @Override
    public void deleteByName(String name) {
        jdbcTemplate.update("delete from USERS where USERNAME = ?", name);
    }

    @Override
    public Integer count() {
        return jdbcTemplate.queryForObject("select count(1) from USERS", Integer.class);
    }

    @Override
    public void deleteAll() {
        jdbcTemplate.update("delete from USERS");
    }
}
